Fix ld segfault for microblaze when --gc-sections is used
Upstream: pending
https://sourceware.org/bugzilla/show_bug.cgi?id=21180

Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>

diff -Nur binutils-2.27.orig/bfd/elf32-microblaze.c binutils-2.27/bfd/elf32-microblaze.c
--- binutils-2.27.orig/bfd/elf32-microblaze.c	2016-08-03 09:36:50.000000000 +0200
+++ binutils-2.27/bfd/elf32-microblaze.c	2017-02-23 19:43:12.612313590 +0100
@@ -3297,13 +3297,20 @@
 	      || h->dynindx == -1))
         {
           asection *sec = h->root.u.def.section;
+	  bfd_vma value;
+
+	  value = h->root.u.def.value;
+	  if (sec->output_section != NULL)
+	    /* PR 21180: If the output section is NULL, then the symbol is no
+	       longer needed, and in theory the GOT entry is redundant.  But
+	       it is too late to change our minds now...  */
+	    value += sec->output_section->vma + sec->output_offset;
+
           microblaze_elf_output_dynamic_relocation (output_bfd,
                                                     srela, srela->reloc_count++,
                                                     /* symindex= */ 0,
                                                     R_MICROBLAZE_REL, offset,
-                                                    h->root.u.def.value
-                                                    + sec->output_section->vma
-                                                    + sec->output_offset);
+                                                    value);
         }
       else
         {
